﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Tomahawk.Runtime.Networking
{
    /// <summary>
    /// The Network Manager is able to handle and update a network service at a time
    /// </summary>
    public class NetworkManager
    {

        NetworkService currentService;

        /// <summary>
        /// Initialization
        /// </summary>
        public void Initialize(Game game)
        {
        }

        /// <summary>
        /// Load a network service into the manager
        /// </summary>
        /// <param name="newService"></param>
        public void LoadService(NetworkService newService)
        {
            //TODO: Handle previous service
            this.currentService = newService;
        }

        /// <summary>
        /// Start a multiplayer game as a host
        /// </summary>
        public void HostGame(float waitTime)
        {
            if (this.currentService != null)
            {
                this.currentService.CreateGame(waitTime);
            }
        }

        /// <summary>
        /// Start a search for games to join
        /// </summary>
        public void JoinGame()
        {
            if (this.currentService != null)
            {
                this.currentService.StartJoinGame();
            }
        }

        /// <summary>
        /// Update the current service
        /// </summary>
        internal void Update(float elapsedTime)
        {
            if (this.currentService != null)
            {
                //update
                this.currentService.Update(elapsedTime);
            }
        }

        /// <summary>
        /// Abort the current service operation
        /// </summary>
        public void Abort()
        {
            if (this.currentService != null)
            {
                this.currentService.Abort();
            }
        }
    }

}
